<!DOCTYPE html>
<#assign ctx=Session.basePath>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加关注</title>
    <script>
        var shipid = '<#if shipid??>${shipid}<#else></#if>';
        var company =  '<#if company??>${company}<#else></#if>';
    </script>
    <link href="${ctx}/easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <link href="${ctx}/easyui/themes/icon.css" rel="stylesheet"/>
    <link href="${ctx}/inspiniain/font-awesome/css/font-awesome.css" rel="stylesheet">
    <script src="${ctx}/easyui/jquery.easyui.min.js"></script>
    <script src="${ctx}/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script>
        function loadAll() {

            var pager = $('#dg').datagrid({
                fitColumns:true,
                fit: true,
                loadFilter: function(data){
                    if(data != null && data.rows != null){
                        for(var i = 0; i < data.rows.length; i++){
                            var record = data.rows[i];
                            var shipname;

                                shipname = record.shipname;

                            var mmsi=record.mmsi;

                            var position = "<a href='#' onclick='locBoat(\""+mmsi+"\")'>"+shipname+"</a>";
                            var track = "<a href='#' onclick='locationMap(\""+mmsi+"\",\""+shipname+"\")'><i class='fa fa-eye'></i></a>";
                            record.position = position;
                            record.track = track;
                            record.mmsi = mmsi;
                            record.shipName = shipname;
                        }
                    }
                    return data;
                }
            });
            var page=$('#dg').datagrid('getPager');
            page.pagination({
                layout:['first','prev','next','last','refresh'],
                showRefresh:true
            });
        }

        function  locBoat(mmsi){
            $.ajax({
                url:"/manage/ship/user/selectLocation",
                data:{mmsi:mmsi},
                type:"POST",
                success:function (data) {
                    var lon = data.lon;
                    var lat = data.lat;
                    if(lon!=null&&lat!=null)
                    {
                        window.parent.locBoat(lon,lat);
                    }else {
                        window.parent.layer.alert("该船暂时无法定位");
                    }
                }
            })
        }



        function locationMap(mmsi,shipname) {

            $.ajax({
                url:"/manage/ship/user/selectLocation",
                data:{mmsi:mmsi},
                type:"POST",
                success:function (data) {
                    var lon = data.lon;
                    var lat = data.lat;
                    var course=data.course;
                    if(lon!=null&&lat!=null)
                    {
                        var trackShip={
                            trackId:mmsi,
                            type:'ais'
                        }
                        window.parent.locMap(lon,lat,trackShip,shipname,course);
                    }else {
                        window.parent.layer.alert("该船暂时无法追踪");
                    }


                }
            })

            //console.log("Longitude: "+lon+";Latitude: "+lat+";shipName: "+shipName);
        }
        $(function () {
            loadAll();
        })
        <#--function dropGuanZhu(sfid) {-->
            <#--$.messager.confirm('确认取关', '是否要取消关注?', function(r){-->
                <#--if (r){-->
                    <#--$.ajax({-->
                        <#--type:'POST',-->
                        <#--url:'${ctx}/ship/guanzhu/dropGuanZhu',-->
                        <#--data:{sfid:sfid},-->
                        <#--success:function (data) {-->
                            <#--if(data){-->
                                <#--loadAll();-->
                            <#--}else{-->
                                <#--layer.alert("取关异常");-->
                            <#--}-->
                        <#--}-->
                    <#--})-->
                <#--}-->
            <#--});-->
        <#--}-->
    </script>
</head>
<body>
<table id="dg",
       data-options="rownumbers:false,singleSelect:true,pagination:true,url:'${ctx}/ship/guanzhu/guanZhuLiebiao?id=${guanid}',method:'post',toolbar:'#tb'">
    <thead>
    <tr>
    <#--<th data-options="field:'loginName',width:80">账号</th>-->
        <th data-options="field:'position',width:110">船名</th>
        <th data-options="field:'mmsi',width:80,align:'center'">MMSI</th>
        <th data-options="field:'track',width:40,align:'center'">追踪</th>
    </tr>
    </thead>
</table>
</body>
</html>